home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / gawk / cawf2st.zoo / error.c < prev    next >
C/C++ Source or Header  |  1992-04-12  |  3KB  |  96 lines

  1. /*
  2.  *      error.c - error handling functions for cawf(1)
  3.  */
  4.  
  5. /*
  6.  *      Copyright (c) 1991 Purdue University Research Foundation,
  7.  *      West Lafayette, Indiana 47907.  All rights reserved.
  8.  *
  9.  *      Written by Victor A. Abell <abe@mace.cc.purdue.edu>,  Purdue
  10.  *      University Computing Center.  Not derived from licensed software;
  11.  *      derived from awf(1) by Henry Spencer of the University of Toronto.
  12.  *
  13.  *      Permission is granted to anyone to use this software for any
  14.  *      purpose on any computer system, and to alter it and redistribute
  15.  *      it freely, subject to the following restrictions:
  16.  *
  17.  *      1. The author is not responsible for any consequences of use of
  18.  *         this software, even if they arise from flaws in it.
  19.  *
  20.  *      2. The origin of this software must not be misrepresented, either
  21.  *         by explicit claim or by omission.  Credits must appear in the
  22.  *         documentation.
  23.  *
  24.  *      3. Altered versions must be plainly marked as such, and must not
  25.  *         be misrepresented as being the original software.  Credits must
  26.  *         appear in the documentation.
  27.  *
  28.  *      4. This notice may not be removed or altered.
  29.  */
  30.  
  31. #include "cawf.h"
  32.  
  33.  
  34. /*
  35.  * Error(t, l, s1, s2) - issue error message
  36.  */
  37.  
  38. void
  39. Error(t, l, s1, s2)
  40.         int t;                          /* type: WARN or FATAL */
  41.         int l;                          /* LINE: display Line[] */
  42.         char *s1, *s2;                  /* optional text */
  43. {
  44.         char msg[MAXLINE];              /* message */
  45.  
  46.         if (l == LINE)
  47.                 (void) fprintf(Efs, "%s: (%s, %d):%s%s - %s\n",
  48.                         Pname,
  49.                         Inname,
  50.                         NR,
  51.                         (s1 == NULL) ? "" : s1,
  52.                         (s2 == NULL) ? "" : s2,
  53.                         Line);
  54.         else
  55.                 (void) fprintf(Efs, "%s:%s%s\n",
  56.                         Pname,
  57.                         (s1 == NULL) ? "" : s1,
  58.                         (s2 == NULL) ? "" : s2);
  59.         if (t == FATAL)
  60.                 exit(1);
  61.         Err = 1;
  62.         return;
  63. }
  64.  
  65.  
  66. /*
  67.  * Error3(len, word, sarg, narg) - process error in pass3
  68.  */
  69.  
  70. void
  71. Error3(len, word, sarg, narg, msg)
  72.         int len;                        /* length (negative is special */
  73.         char *word;                     /* word */
  74.         char *sarg;                     /* string argument */
  75.         int narg;                       /* numeric argument */
  76.         char *msg;                      /* message */
  77. {
  78.         if (len == MESSAGE) {
  79.                 (void) fprintf(Efs, "%s: (%s, %d) %s\n",
  80.                         Pname,
  81.                         (word == NULL) ? "<none>" : word,
  82.                         narg,
  83.                         (sarg == NULL) ? "<none>" : sarg);
  84.                 return;
  85.         }
  86.         (void) fprintf(Efs,
  87.                 "%s: pass3, len=%d, word=\"%s\", sarg=\"%s\", narg=%d%s%s\n",
  88.                 Pname, len,
  89.                 (word == NULL) ? "" : word,
  90.                 (sarg == NULL) ? "" : sarg,
  91.                 narg,
  92.                 (msg == NULL) ? "" : " - ",
  93.                 (msg == NULL) ? "" : msg);
  94.         Err = 1;
  95. }
  96.